package org.nanhill.xmlro.sro.model;

import java.util.Iterator;
import java.util.Map;

import org.nanhill.xmlro.Serializer;
import org.nanhill.xmlro.XmlroException;
import org.nanhill.xmlro.XmlroOutput;

/**
 * Serializing a java.util.Map.
 * 
 * @author alin
 * 
 */
public class MapSerializer implements Serializer {
	public void writeObject(Object obj, XmlroOutput out) throws XmlroException {
		Map map = (Map) obj;
		out.writeMapBegin();
		Iterator iter = map.keySet().iterator();
		while (iter.hasNext()) {
			Object key = iter.next();
			out.writeObject(key);
			out.writeObject(map.get(key));
		}
		out.writeMapEnd();
	}
}
